package com.bs.biaoge.util;

import com.bs.biaoge.entity.User;
import com.bs.biaoge.util.excel.ExcelModelPropertyValue;
import com.bs.biaoge.util.excel.ExcelProperty;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * @author 小姚
 * @pakeageName:com.bs.biaoge.util
 * @ClassName:ExcelGetListUser
 * @Descirption:
 * @data 2023/3/4 23:37
 */
public class ExcelGetListUser {
    public static List<User> getExcelObj() throws FileNotFoundException, IllegalAccessException, InvocationTargetException, InstantiationException {
        FileInputStream stream=new FileInputStream("D:\\学生表.xlsx");
        Map<String, List<Object[]>> map = ExcelUtil.getExcelMap(stream);
        //创建验证excel模板类
        ExcelModelPropertyValue propertyValue=new ExcelModelPropertyValue();
        //创建获取实体类中的属性
        List<User> list=new ArrayList<>();
        ExcelProperty<User> excelProperty=new ExcelProperty<>();
        String[] property = excelProperty.getProperty(User.class);
        boolean excelModel = propertyValue.getExcelModel(property, map);
        if(!excelModel){
            return list;
        }
        //创建返回的类型：list
        for (Map.Entry<String, List<Object[]>> stringListEntry : map.entrySet()) {
            List<Object[]> value = stringListEntry.getValue();
            Object[] objects = value.get(0);
            System.out.println("objs的长度-----------"+objects.length);
            String[] pros=new String[objects.length];
            for(int i=0;i<property.length;i++){
                for(int j=0;j<objects.length;j++){
                   if(property[i].equals(property[j])){
                       pros[i]=property[i];
                       System.out.println("耶耶耶-----"+pros[i]);
                   }
                }
            }
            for (Object[] objects1 : value) {

               /* for (Object object : objects) {
                    for (String s : property) {
                        if(s.equals(object)){
                            System.out.println("进来了-----");
                            System.out.println("objym呀呀呀------"+s);
                        }
                    }
                }*/
                    if(Arrays.equals(objects,objects1))continue;
                    // propertyValue.getExcelModel(objects, map);
                    User user = excelProperty.getPropertyValue(User.class, objects1);
                System.out.println("我是user的值啊--------"+user);
                    String age = user.getAge();
                    list.add(user);


            }

        }
        System.out.println("我是list的长度------"+list.size());

        return list;
    }

    public static void main(String[] args) throws InvocationTargetException, FileNotFoundException, InstantiationException, IllegalAccessException {
        List<User> users = getExcelObj();
        for (User user : users) {
            System.out.println(user);
        }
    }
}
